//
//  UIButton+button.m
//  Goddess
//
//  Created by bigbang进哥哥 on 17/4/19.
//  Copyright © 2017年 bigbang进哥哥. All rights reserved.
//

#import "UIButton+button.h"

@implementation UIButton (button)

+ (UIButton *)creatButtonTitle:(NSString *)title
                backgroundColor:(UIColor*)color
                  setTitleColor:(UIColor *)TitleColor
             setTitleLabelFont:(UIFont *)font
                      addTarget:(id)target
                         action:(SEL)action
               forControlEvents:(UIControlEvents)controlEvents
{
    
    UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:title forState:UIControlStateNormal];
    button.backgroundColor = color;
    [button setTitleColor:TitleColor forState:UIControlStateNormal];
    button.titleLabel.font = font;
    [button addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents];
    
    return button;
}

#pragma mark - < 验证码倒计时按钮 >
- (void)yanzhengmaTimeforNumber:(NSNumber *)time{
    if ([time isEqual:@0]) {
        [self setTitle:NSLocalizedString(@"Get Code_00", nil) forState:UIControlStateNormal];
        self.enabled = YES;
        [[NSNotificationCenter defaultCenter] postNotificationName:@"YZM" object:nil];
    }
    else
    {
        [self setTitle:[NSString stringWithFormat:@"%@s",time] forState:UIControlStateNormal];
        NSNumber * t = [NSNumber numberWithInt:[time intValue]-1];
        [self performSelector:@selector(yanzhengmaTimeforNumber:) withObject:t afterDelay:1];
        self.enabled = NO;
    }
}

@end
